package cn.tedu.mintmall.service.Impl;

import cn.tedu.mintmall.dto.ProductDTO;
import cn.tedu.mintmall.mapper.ProductMapper;
import cn.tedu.mintmall.service.IProductService;
import cn.tedu.mintmall.vo.ProductVO;
import com.github.pagehelper.PageHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class ProductServiceImpl implements IProductService {
    @Autowired
    private ProductMapper productMapper;


    //模糊查询根据标题
    @Override
    public List<ProductVO> selectByObscureTitle(ProductDTO productDTO) {
        if (productDTO.getTitle() == null || (productDTO.getTitle().trim().isEmpty())){
            log.error("根据标题模糊搜索不能为空也不能只有空格");
        }
        PageHelper.startPage(productDTO.getPage(), productDTO.getPageSize());
        List<ProductVO> productVOS = productMapper.selectByObscureTitle(productDTO);
        return productVOS;
    }

    //根据类别id查询商品
    @Override
    public List<ProductVO> selectByCategoryId(ProductDTO productDTO) {
        PageHelper.startPage(productDTO.getPage(), productDTO.getPageSize());
        List<ProductVO> productVOS = productMapper.selectProductByCategoryId(productDTO);
        return productVOS;
    }

    //根据图片id查询商品
    @Override
    public List<ProductVO> selectByImgId(ProductDTO productDTO) {
        PageHelper.startPage(productDTO.getPage(), productDTO.getPageSize());
        List<ProductVO> productVOS = productMapper.selectProductByImgId(productDTO);
        return productVOS;
    }
}
